<?php
   
   //获取推荐文章
   function tuijian($cid,$num)
   {  
      $where=array('cid'=>$cid);
      $data=D("NewsView")->where($where)->limit($num)->order("pv desc")->select();
      return $data;
   }

     //内容页生成
  function show_url2($data)
  {
    $uid=session("user.id");
    if($uid){ 
       $uid= "/".$uid;
    }
    $yumi= $data['yumi_url'];
    return U("/Article/show/".$data['id'],'','',$yumi).$uid;
  }


  //取随机混合字母数字  
  function getCode($iCount) {  
  $arrChar = "012qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM3456789";
  $code="";
    for ( $i = 0; $i < $iCount; $i++ )  
  { 
    $code .= $arrChar[ mt_rand(0, strlen($arrChar) - 1) ];  
  }  
  return $code;
  }
  
  
   function getNum($iCount) {  
  $arrChar = "0123456789";
  $code="";
    for ( $i = 0; $i < $iCount; $i++ )  
  { 
    $code .= $arrChar[ mt_rand(0, strlen($arrChar) - 1) ];  
  }  
  return $code;
  }
  

  //上一页
  function show_last($id,$cid=null)
  {  
     $data=M("news")->where("id >".$id)->order("id asc")->find();
     if(empty($data)){
       return "javascript:alert('这已经是第一篇拉!')";
     }else{
      $yumi_url= M('yumi')->where("id =".$data['yumi_id'])->field("url")->find();
      $data['yumi_url']=$yumi_url['url'];
      return show_url2($data);
     }
  }
  

  //下一页
  function show_next($id,$cid=null)
  {  
     $data=M("news")->where("id <".$id)->order("id desc")->find();
     if(empty($data)){
       return "javascript:alert('这已经是最后一篇拉!')";
     }else{
      $yumi_url= M('yumi')->where("id =".$data['yumi_id'])->field("url")->find();
      $data['yumi_url']=$yumi_url['url'];
      return show_url2($data);
     }
  }
  

  //获取最小的套餐价格
  function min_price($array){
        $a=array();
        foreach ($array as $v) {
           $a[]=$v['price'];
         }
         return min($a);
  }
  

  //获取商品链接
 function get_item_url($item_id,$news_id=null)
  {
    $user=session('user');
    $uid=$user['id'];
    if($news_id){
       $news= M('shop_news')->where(array('id'=>$news_id))->find();
       $yumi=M('yumi')->where(array('id'=>$news['yumi_id']))->find();
       $url= U("/buy/".$item_id."/".$uid,'','',$yumi['url']);
       $url=$url."?news_id=".$news_id;
     }else{
       $yumi=M('yumi')->where(array('type'=>2))->order("Rand()")->find();
       $url= U("/buy/".$item_id."/".$uid,'','',$yumi['url']);
     }
     return $url;
  }



?>